package com.learn.eduorder.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.learn.eduapi.entity.UserCourseOrder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface OrderMapper extends BaseMapper<UserCourseOrder> {

    /**
     * 插入订单（测试分库分表）
     * @param order
     * @return
     */
   void insertOrder(UserCourseOrder order);

    /**
     * 按多个id查询订单
     * @param ids
     * @return
     */
   List<UserCourseOrder> selectOrdersByIds(@Param("ids") List<Long> ids);

    /**
     * 修改订单状态
     * @param tradeNo
     * @param status
     */
    @Update("update user_course_order set status = #{status} where trade_no = #{tradeNo}")
    void updateOrderStatus(@Param("tradeNo") String tradeNo,@Param("status") long status);

    /**
     * 查询用户订单
     * @param userId
     * @return
     */
    @Select("select * from user_course_order where user_id = #{userId}")
    List<UserCourseOrder> selectOrdersByUserId(@Param("userId")long userId);

    /**
     * 查询订单号订单
     * @return
     */
    @Select("select * from user_course_order where trade_no = #{tradeNo}")
    UserCourseOrder selectOrderByTradeNo(@Param("tradeNo")String tradeNo);

}
